package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbUserScoreAccountMapper;
import com.dongdongshop.pojo.TbUserScoreAccount;
import com.dongdongshop.service.ScoreService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

@Service
@DubboService
public class ScoreServiceImpl implements ScoreService {

    @Resource
    private TbUserScoreAccountMapper scoreAccountMapper;

    @Override
    public TbUserScoreAccount selectByUserId(Long uId) {
        return scoreAccountMapper.selectByUserId(uId);
    }

    @Override
    public int addScore(TbUserScoreAccount score) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        score.setCreateTime(date);
        return scoreAccountMapper.insertSelective(score);
    }

    @Override
    public int updateScore(TbUserScoreAccount score) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        score.setUpdateTime(date);
        return scoreAccountMapper.updateByPrimaryKeySelective(score);
    }
}
